import request from '@/utils/request'
import qs from 'qs'
import axios from 'axios'

const systemprefix = '/uums'
const systemprefix1 = '/zcm'
export function loginByUsername(username, password) {
  const data = {
    'username': username,
    'password': password,
    'client_id': process.env.CLIENT_ID,
    'client_secret': process.env.CLIENT_SECRET,
    'grant_type': process.env.GRANT_TYPE
  }
  const search = qs.stringify(data)
  return request({
    url: '/oauth/token',
    method: 'post',
    data: search
  })
}
export function searchApproveList(postselectinfo) {
  return request({
    url: systemprefix + '/System/SysGroupUser/selectExistUser?groupId=' + postselectinfo.groupId + "&orgId=''",
    method: 'post',
    data: postselectinfo
  })
}

// 待编查询下一审核人
export function searchApproveListbian(postselectinfo) {
  // 待审查下一审核人
  if (postselectinfo.Userid && postselectinfo.ArticleId && postselectinfo.WorkitemInsId) {
    let Userid = postselectinfo.Userid
    let ArticleId = postselectinfo.ArticleId
    let WorkitemInsId = postselectinfo.WorkitemInsId
    const canshu = {
      'userid': Userid,
      'id': ArticleId,
      'workitem_ins_id': WorkitemInsId
    }
    return request({
      url: systemprefix1 + '/zcm/nrsh/queryNextAuditorLC',
      method: 'post',
      data: canshu
    })
  } else {
    return request({
      // 待编查下一审核人
      url: systemprefix1 + '/zcm/nrbj/getMainUserListOfSubmit/' + postselectinfo.Userid + '/' + postselectinfo.ArticleId + '/' + postselectinfo.type,
      method: 'post',
      data: postselectinfo
    })
  }
}
// 原来的
// export function searchApproveListbian(postselectinfo) {

//     return request({
//       url: systemprefix1+ '/zcm/nrbj/getMainUserListOfSubmit/' + postselectinfo.groupId ,
//       method: 'post',
//       data: postselectinfo
//     })

// }

export function logout(token) {
  return request({
    url: '/oauth/ext/revokeToken?token=' + token,
    method: 'post'
  })
}

export function getUserInfo(token) {
  return request({
    url: systemprefix + '/common/user/getUserAllInfo',
    method: 'post'
  })
}

export function refreshToken(refreshToken) {
  /* -----用户名密码登录 begin----- */
  const data = {
    refresh_token: refreshToken,
    'client_id': process.env.CLIENT_ID,
    'client_secret': process.env.CLIENT_SECRET,
    'grant_type': 'refresh_token'
  }
  /* -----用户名密码登录 end----- */
  // const data = {
  //   refresh_token: refreshToken,
  //   'client_id': 'https://100001',
  //   'client_secret': '100001abcdeft',
  //   'grant_type': 'refresh_token'
  // }
  // grant_type=refresh_token
  // client_id=https://100001
  // client_secret=100001abcdeft
  // refresh_token=RT-3-px5XIduv-Ps-HlRnEpVPqaC2Npp7WrRn
  /* -----用户名密码登录 begin----- */
  const search = qs.stringify(data)

  return request({
    url: '/oauth/token',
    method: 'post',
    data: search
  })
  /* -----用户名密码登录 end----- */
  // return axios.get(process.env.CERTIFICATION_API + '/oauth2.0/accessToken?grant_type=refresh_token&client_id=http://100001&client_secret=100001abcdeft&refresh_token=' + refreshToken)
  // return request({
  //   url: '/api/cas/oauth2.0/accessToken?grant_type=refresh_token&client_id=https://100001&client_secret=100001abcdeft&refresh_token=RT-13-aUWDMes3pQH3GYDbIvEhKiC-thuYhoDf',
  //   method: 'get'
  // })
}

